<template>
  <div>
    <!--  面包屑导航区域-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图  -->
    <el-card>
<!--      搜索框-->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入你要搜索的关键字" v-model="queryInfo.query" clearable
                    @clear="getOrderList" >
            <el-button slot="append" icon="el-icon-search"  @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
<!--    表格区域-->
      <el-table :data="orderList" border stripe>
        <!-- stripe: 斑马条纹border：边框-->
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格（元）" width="120px"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款"  width="95px">
          <template slot-scope="scope">
            <el-button size="mini" type="warning" plain disabled v-if="scope.row.order_pay=== '0'">未付款</el-button>
            <el-button size="mini" type="success" disabled v-else>已付款</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"  width="95px"></el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="150px">
          <template slot-scope="scope">
            <!--          // | dataFormat 时间格式过滤器-->
            {{scope.row.create_time | dataFormat}}
          </template>
        </el-table-column>
        <!--    作用域插槽    scope.row得到这一行所有数据
         @change="userStateChanged(scope.row)监听变化 触发函数-->
        <el-table-column label="操作" width="120px">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              circle
              @click="showEditDialog"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              circle
              @click="dialogprogressVisible =true"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
<!--      分页区域-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[5, 10, 20]"
        :page-size="this.queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.total">
      </el-pagination>
    </el-card>
<!--    修改地址对话框-->
    <el-dialog
      title="修改地址"
      :visible.sync="dialogAddressVisible" @close="dialogAddressClose"
      width="50%">
      <el-form :model="AddressForm" :rules="AddressFormRules" ref="AddressFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省市区/县" prop="Address1">
        <el-cascader
          v-model="AddressForm.Address1"
          :options="citydata"
          :props="props" style="width: 100%"
          @change="handleChange" clearable>
        </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="Address2">
          <el-input v-model="AddressForm.Address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogAddressVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogAddressVisible = false">确 定</el-button>
  </span>
    </el-dialog>
<!--   查看物流进度对话框-->
    <el-dialog title="物流进度" :visible.sync="dialogprogressVisible" width="50%">
      <div class="block">
        <div class="radio" style="margin-bottom: 15px">
          排序：
          <el-radio-group v-model="reverse">
            <el-radio :label="true">倒序</el-radio>
            <el-radio :label="false">正序</el-radio>
          </el-radio-group>
        </div>

        <el-timeline :reverse="reverse">
          <el-timeline-item
            v-for="(progress, index) in progressData"
            :key="index"
            :timestamp="progress.time">
            {{progress.context}}
          </el-timeline-item>
        </el-timeline>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import citydata from './citydata'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      // 订单列表
      orderList: [],
      // citydata城市省市区
      citydata: citydata,
      // 修改地址对话框开关
      dialogAddressVisible: false,
      // 级联选择框中的属性
      props: {
        expandTrigger: 'hover',
        value: 'value',
        label: 'label',
        children: 'children'
      },
      // 地址表单
      AddressForm: {
        Address1: [],
        Address2: ''
      },
      // 验证地址表单规则
      AddressFormRules: {
        Address1: [
          { required: true, message: '请选择省市区', trigger: 'blur' }],
        Address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }]
      },
      // 物流进度对话框开关
      dialogprogressVisible: false,
      // 物流信息
      progressData: [
        {
          time: '2018-05-10 09:39:00',
          ftime: '2018-05-10 09:39:00',
          context: '已签收,感谢使用顺丰,期待再次为您服务',
          location: ''
        },
        {
          time: '2018-05-10 08:23:00',
          ftime: '2018-05-10 08:23:00',
          context: '[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件',
          location: ''
        },
        {
          time: '2018-05-10 07:32:00',
          ftime: '2018-05-10 07:32:00',
          context: '快件到达 [北京海淀育新小区营业点]',
          location: ''
        },
        {
          time: '2018-05-10 02:03:00',
          ftime: '2018-05-10 02:03:00',
          context: '快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]',
          location: ''
        },
        {
          time: '2018-05-09 23:05:00',
          ftime: '2018-05-09 23:05:00',
          context: '快件到达 [北京顺义集散中心]',
          location: ''
        },
        {
          time: '2018-05-09 21:21:00',
          ftime: '2018-05-09 21:21:00',
          context: '快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]',
          location: ''
        },
        {
          time: '2018-05-09 13:07:00',
          ftime: '2018-05-09 13:07:00',
          context: '顺丰速运 已收取快件',
          location: ''
        },
        {
          time: '2018-05-09 12:25:03',
          ftime: '2018-05-09 12:25:03',
          context: '卖家发货',
          location: ''
        },
        {
          time: '2018-05-09 12:22:24',
          ftime: '2018-05-09 12:22:24',
          context: '您的订单将由HLA（北京海淀区清河中街店）门店安排发货。',
          location: ''
        },
        {
          time: '2018-05-08 21:36:04',
          ftime: '2018-05-08 21:36:04',
          context: '商品已经下单',
          location: ''
        }
      ],
      //  物流时间线reverse: true,
      reverse: true

    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      console.log(res)
      if (res.meta.status !== 200) { return this.$message.error('查询订单列表失败！') }
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 监听页码pageSize发生变化
    handleSizeChange(pageSize) {
      this.queryInfo.pagesize = pageSize
      this.getOrderList()
    },
    // 监听当前页CurrentSize发生变化
    handleCurrentChange(CurrentSize) {
      this.queryInfo.pagenum = CurrentSize
      this.getOrderList()
    },
    // 监听级联选择器变化事件
    handleChange(value) {
      // console.log(value)
      this.AddressForm.Address1 = value
    },
    // 显示编辑地址对话框
    showEditDialog() {
      this.dialogAddressVisible = true
    },
    // 监听编辑地址对话框关闭事件
    dialogAddressClose() {
      // 重置表单
      this.$refs.AddressFormRef.resetFields()
    }
    // 显示物流对话框
    // async showProgressDialog () {
    //   // const id = '804909574412544580'
    //   // const id = '1106975712662'
    //   // 获取物流信息1106975712662
    //   // TODO 这个地方接口没有用 自己造数据
    //   // const { data: res } = await this.$http.get('/kuaidi/1106975712662')
    //   // console.log(res)
    //
    // }
  }

}
</script>

<style scoped>

</style>
